package com.mc2.docapp.disabilityassessmenttool;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.mc2.docapp.disabilityassessmenttool.Misc.Additional_Info_DTO;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;

public class AdditionalInfo extends AppCompatActivity {

    public static Map<String, List<Class>> activityFLow;
    public static Additional_Info_DTO additionalInfoDTO = new Additional_Info_DTO();
    public static Additional_Info_DTO additionalInfoDTO2;
    public static ArrayList<List<Class>> classs;
    public static List<Class> routerList;
    CheckBox rtUpLimb;
    CheckBox ltUpLimb;
    CheckBox rtLoLimb;
    CheckBox ltLoLimb;
    CheckBox spinNeu;
    CheckBox congin;
    CheckBox cerebrlPlsy;
    CheckBox amputation;
    CheckBox dwarfi;
    RadioGroup radioGroupDef;
    RadioButton radioGroupIsDefTreatable;

    RadioGroup radioGroupTreatment;
    RadioButton radioButtonIsTreamentComplete;

    RadioGroup isRevaluationrequired;
    RadioButton radioButtonisRevaluationrequired;


    private String[] removeThese = new String[9];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_additional_info);

        rtUpLimb = (CheckBox) findViewById(R.id.cb1);
        ltUpLimb = (CheckBox) findViewById(R.id.cb2);
        rtLoLimb = (CheckBox) findViewById(R.id.cb3);
        ltLoLimb = (CheckBox) findViewById(R.id.cb4);
        spinNeu = (CheckBox) findViewById(R.id.cb5);
        congin = (CheckBox) findViewById(R.id.cb6);
        cerebrlPlsy = (CheckBox) findViewById(R.id.cb7);
        amputation = (CheckBox) findViewById(R.id.cb8);
        dwarfi = (CheckBox) findViewById(R.id.cb9);
        radioGroupDef = (RadioGroup) findViewById(R.id.radioGroupIsDefTreatable);
        radioGroupTreatment = (RadioGroup) findViewById(R.id.IstreatmentComplete);
        isRevaluationrequired = (RadioGroup) findViewById(R.id.isRevaluationrequired);

        rtUpLimb.setChecked(true);
        ltUpLimb.setChecked(true);
        rtLoLimb.setChecked(true);
        ltLoLimb.setChecked(true);
        spinNeu.setChecked(true);
        congin.setChecked(true);
        cerebrlPlsy.setChecked(true);
        amputation.setChecked(true);
        dwarfi.setChecked(true);

        Button saveNnext = (Button) findViewById(R.id.saveAndNext);
        saveNnext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                radioGroupIsDefTreatable = (RadioButton) findViewById(radioGroupDef.getCheckedRadioButtonId());
                String ss = radioGroupIsDefTreatable.getText().toString();
                if (ss.equals("Yes")) {
                    additionalInfoDTO.setDeformityTreatable(true);
                } else {
                    additionalInfoDTO.setDeformityTreatable(false);
                }

                radioButtonisRevaluationrequired = (RadioButton) findViewById(isRevaluationrequired.getCheckedRadioButtonId());
                String revaluationTime = radioButtonisRevaluationrequired.getText().toString();
                additionalInfoDTO.setRevaluationRequired(revaluationTime);

                radioButtonIsTreamentComplete = (RadioButton) findViewById(radioGroupTreatment.getCheckedRadioButtonId());
                String isTreamentComplete = radioButtonIsTreamentComplete.getText().toString();
                if (isTreamentComplete.equals("Yes")) {
                    additionalInfoDTO.setTreatmentComplete(true);
                } else {
                    additionalInfoDTO.setTreatmentComplete(false);
                }

                //String radiovalue = ((RadioButton) findViewById(radioGroupIsDefTreatable.getCheckedRadioButtonId())).getText().toString();

                if (!rtUpLimb.isChecked()) {
                    removeThese[0] = rtUpLimb.getText().toString();
                }

                if (!ltUpLimb.isChecked()) {
                    removeThese[1] = ltUpLimb.getText().toString();
                }

                if (!rtLoLimb.isChecked()) {
                    removeThese[2] = rtLoLimb.getText().toString();
                }
                if (!ltLoLimb.isChecked()) {
                    removeThese[3] = ltLoLimb.getText().toString();
                }

                if (!spinNeu.isChecked()) {
                    removeThese[4] = spinNeu.getText().toString();
                }

                if (!congin.isChecked()) {
                    removeThese[5] = congin.getText().toString();
                }

                if (!cerebrlPlsy.isChecked()) {
                    removeThese[6] = cerebrlPlsy.getText().toString();
                }
                if (!amputation.isChecked()) {
                    removeThese[7] = amputation.getText().toString();
                }
                if (!dwarfi.isChecked()) {
                    removeThese[8] = dwarfi.getText().toString();
                }


                if (routerList != null) routerList.clear();
                additionalInfoDTO2 = new Additional_Info_DTO(removeThese);
                removeThese = new String[9];
                activityFLow = additionalInfoDTO2.getH();
                classs = new ArrayList<List<Class>>(activityFLow.values());
                routerList = new ArrayList<Class>();
                for (List<Class> h :
                        classs) {
                    for (Class d :
                            h) {
                        routerList.add(d);
                    }
                }
                LinkedHashSet<Class> rout = new LinkedHashSet<>(routerList);
                routerList.clear();
                routerList = new ArrayList<Class>(rout);


                Intent intent = new Intent(AdditionalInfo.this, /*router(CerebralPalsy.class)*/NewPatient.class);
                startActivity(intent);

            }

        });
    }

}